package com.laowang.common.utils;

import com.alibaba.fastjson.JSONObject;

import com.laowang.common.exception.CustomException;
import com.laowang.common.utils.aip.*;
import com.laowang.common.utils.http.HttpKit;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.web.multipart.MultipartFile;


import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Auther laowang
 * @Date 2023/5/8
 * @Description
 */

@Slf4j
public class Sample {

    /**
     * 15位身份证号
     */
    private static final Integer FIFTEEN_ID_CARD=15;
    /**
     * 18位身份证号
     */
    private static final Integer EIGHTEEN_ID_CARD=18;
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

    static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
    public static final String apikey = "KUsiyOITPlnph4BX1RMRKtQw";
    public static final String apiSecrect = "px7NFxZSYe6FdjeEvoj2Ww9YcpPnZXGx";


    public static void get() throws IOException {
        String url = "https://aip.baidubce.com/oauth/2.0/token?client_id=%s&sclient_secret=%s&grant_type=client_credentials";

        String format = String.format(url, apikey, apiSecrect);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
            .url(format)
            .method("POST", body)
            .addHeader("Content-Type", "application/json")
            .addHeader("Accept", "application/json")
            .build();
        Response response = HTTP_CLIENT.newCall(request).execute();
        System.out.println(response.body().string());

    }

    public static void main(String[] args) throws IOException {
        //String token = getToken();
        //vehicleLicense("");
        //marriageCertificate();
        //test1();

    }

    public static Map<String,String> getToken() {

        //APIKey和SecretKey需要你在百度智能云平台添加应用拿到这两个值

        String str = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + apikey + "&client_secret=" + apiSecrect;
        try {
            URL url = null;
            try {
                url = new URL(str);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            URLConnection connectionData = null;
            try {
                connectionData = url.openConnection();
            } catch (IOException e) {
                e.printStackTrace();
            }
            connectionData.setConnectTimeout(2000);
            BufferedReader br = new BufferedReader(new InputStreamReader(connectionData.getInputStream(), "UTF-8"));
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
            //System.out.println(sb.toString());
            Map<String,String> map = JSONObject.parseObject(sb.toString(), Map.class);
            log.error("返回的值:{}",map);
            //{access_token=24.3f218de54b142f9f139ef9ecf1356d7d.2592000.1686105797.282335-33232970,
            // refresh_token=25.3b1fb784261487fa4368e0c2f1c3af06.315360000.1998873797.282335-33232970,
            // scope=public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_form brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_台湾通行证 vis-ocr_港澳通行证 vis-ocr_机动车购车发票识别 vis-ocr_机动车检验合格证识别 vis-ocr_车辆vin码识别 vis-ocr_定额发票识别 vis-ocr_保单识别 vis-ocr_机打发票识别 vis-ocr_行程单识别 brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_invoice brain_ocr_vehicle_certificate brain_ocr_air_ticket brain_ocr_invoice brain_ocr_insurance_doc brain_formula brain_seal brain_ocr_facade brain_ocr_meter brain_doc_analysis brain_ocr_webimage_loc brain_bus_ticket brain_toll_invoice brain_ocr_medical_paper brain_ocr_doc_analysis_office brain_ferry_ticket brain_vat_invoice_verification brain_ocr_used_vehicle_invoice brain_ocr_medical_detail brain_vehicle_registration_certificate brain_ocr_online_taxi_itinerary brain_ocr_multi_idcard brain_ocr_mixed_multi_vehicle brain_ocr_weigth_note brain_ocr_ multiple_invoice brain_ocr_social_security_card brain_ocr_medical_report_detection brain_ocr_waybill brain_ocr_medical_summary brain_ocr_brain_shopping_receipt brain_ocr_road_transport_certificate brain_form_table brain_ocr_remove_handwriting brain_ocr_ doc_crop_enhance brain_ocr_health_code brain_ocr_covid_test brain_ocr_health_report brain_ocr_three_factors_verification brain_ocr_bank_receipt_new brain_ocr_marriage_certificate brain_ocr_hk_macau_taiwan_exitentrypermit wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx, session_key=9mzdCKJFuMLkmxJjMwSIlXf/61/9WNJWXdN5MHnUAf1D/+PllKbJ/MjTIm8eM3N8AySIO+RnhC2y1jmOF5KPzt3bkDJi1w==,
            // expires_in=2592000,
            // session_secret=28d347164101e89ca130f95cdb15176c}

            return   map;
        } catch (Exception e) {

        }
        return null;
    }

    /**
     * 户口本识别
     * @param filePath
     * @return
     */
    public static BusinessLicense test2(String filePath) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license";
        try {
            // 本地文件路径
            //String filePath = "C:\\Users\\Administrator\\Desktop\\新建文件夹\\微信图片_20230505094121.jpg";
            byte[] imgData = FileUtil.readFileByBytes1(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = getToken().get("access_token");

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println(result);
            //{"words_result_num":14,"words_result":{"姓名_男":[{"word":"蒋胜"}],"身份证件号_男":[{"word":"430421198903137551"}],"出生日期_男":[{"word":"1989年03月13日"}],"国籍_男":[{"word":"中国"}],"性别_男":[{"word":"男"}],"姓名_女":[{"word":"王晶"}],"身份证件号_女":[{"word":"430421198912190143"}],"出生日期_女":[{"word":"1989年12月19日"}],"国籍_女":[{"word":"中国"}],"性别_女":[{"word":"女"}],"结婚证字号":[{"word":"J430111-2013-002354"}],"持证人":[{"word":"蒋胜"}],"备注":[{"word":""}],"登记日期":[{"word":"2013年04月22日"}]},"log_id":1700045308982347920}
            IdCardObj idCardObj = JSONObject.parseObject(result, IdCardObj.class);
            String words_result = idCardObj.getWords_result();
            BusinessLicense businessLicense = new BusinessLicense();
            Map<String,String> map = JSONObject.parseObject(words_result, Map.class);
            for (String s : map.keySet()) {
                //System.out.println("key:"+s);

                Map<String,String> mapName = JSONObject.parseObject(JSONObject.toJSONString(map.get(s)), Map.class);
                //System.out.println("mapName:"+mapName);
                if (s.equals("经营范围")){
                    businessLicense.set经营范围(mapName.get("words"));
                }
                if (s.equals("法人")){
                    businessLicense.set法人(mapName.get("words"));
                }
                if (s.equals("证件编号")){
                    businessLicense.set证件编号(mapName.get("words"));
                }

                if (s.equals("单位名称")){
                    businessLicense.set单位名称(mapName.get("words"));
                }
                if (s.equals("社会信用代码")){
                    businessLicense.set社会信用代码(mapName.get("words"));
                }
                if (s.equals("社会信用代码")){
                    businessLicense.set地址(mapName.get("words"));
                }

            }

            System.out.println("营业执照:"+businessLicense);
            return businessLicense;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     *
     * @return
     *  识别营业执照
     */
    public static BusinessLicense test1(String filePath) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license";
        try {
            // 本地文件路径
            //String filePath = "C:\\Users\\Administrator\\Desktop\\新建文件夹\\微信图片_20230505094121.jpg";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = getToken().get("access_token");

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println(result);
            //{"words_result_num":14,"words_result":{"姓名_男":[{"word":"蒋胜"}],"身份证件号_男":[{"word":"430421198903137551"}],"出生日期_男":[{"word":"1989年03月13日"}],"国籍_男":[{"word":"中国"}],"性别_男":[{"word":"男"}],"姓名_女":[{"word":"王晶"}],"身份证件号_女":[{"word":"430421198912190143"}],"出生日期_女":[{"word":"1989年12月19日"}],"国籍_女":[{"word":"中国"}],"性别_女":[{"word":"女"}],"结婚证字号":[{"word":"J430111-2013-002354"}],"持证人":[{"word":"蒋胜"}],"备注":[{"word":""}],"登记日期":[{"word":"2013年04月22日"}]},"log_id":1700045308982347920}
            IdCardObj idCardObj = JSONObject.parseObject(result, IdCardObj.class);
            String words_result = idCardObj.getWords_result();
            BusinessLicense businessLicense = new BusinessLicense();
            Map<String,String> map = JSONObject.parseObject(words_result, Map.class);
            for (String s : map.keySet()) {
                //System.out.println("key:"+s);

                Map<String,String> mapName = JSONObject.parseObject(JSONObject.toJSONString(map.get(s)), Map.class);
                //System.out.println("mapName:"+mapName);
                if (s.equals("经营范围")){
                    businessLicense.set经营范围(mapName.get("words"));
                }
                if (s.equals("法人")){
                    businessLicense.set法人(mapName.get("words"));
                }
                if (s.equals("证件编号")){
                    businessLicense.set证件编号(mapName.get("words"));
                }

                if (s.equals("单位名称")){
                    businessLicense.set单位名称(mapName.get("words"));
                }
                if (s.equals("社会信用代码")){
                    businessLicense.set社会信用代码(mapName.get("words"));
                }
                if (s.equals("社会信用代码")){
                    businessLicense.set地址(mapName.get("words"));
                }

            }

            System.out.println("营业执照:"+businessLicense);
            return businessLicense;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     *
     * @return
     *  识别结婚证
     */
    public static PersonInfo marriageCertificate(String filePath) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/marriage_certificate";
        try {
            // 本地文件路径
            //String filePath = "C:\\Users\\Administrator\\Desktop\\7ff3dc64be7f46358df21f5355c87049.jpg";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = getToken().get("access_token");

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println(result);
            //{"words_result_num":14,"words_result":{"姓名_男":[{"word":"蒋胜"}],"身份证件号_男":[{"word":"430421198903137551"}],"出生日期_男":[{"word":"1989年03月13日"}],"国籍_男":[{"word":"中国"}],"性别_男":[{"word":"男"}],"姓名_女":[{"word":"王晶"}],"身份证件号_女":[{"word":"430421198912190143"}],"出生日期_女":[{"word":"1989年12月19日"}],"国籍_女":[{"word":"中国"}],"性别_女":[{"word":"女"}],"结婚证字号":[{"word":"J430111-2013-002354"}],"持证人":[{"word":"蒋胜"}],"备注":[{"word":""}],"登记日期":[{"word":"2013年04月22日"}]},"log_id":1700045308982347920}
            IdCardObj idCardObj = JSONObject.parseObject(result, IdCardObj.class);
            String words_result = idCardObj.getWords_result();

            PersonInfo personInfo = JSONObject.parseObject(words_result, PersonInfo.class);
            String 姓名_男 = personInfo.get姓名_男();
            String 姓名_女 = personInfo.get姓名_女();
            List<WordsObject> wordsObjects = JSONObject.parseArray(姓名_男, WordsObject.class);
            List<WordsObject> wordsObjects1 = JSONObject.parseArray(姓名_女, WordsObject.class);
            if (wordsObjects.size()>0){
                personInfo.set姓名_男(wordsObjects.get(0).getWord());
            }else {
                throw new CustomException("结婚证识别有误",400);
            }
            if (wordsObjects1.size()>0){
                personInfo.set姓名_女(wordsObjects1.get(0).getWord());
            }else {
                throw new CustomException("结婚证识别有误",400);
            }

            System.out.println("结婚证信息:"+personInfo);
            return personInfo;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    //识别身份证
    public static IdCard idcard(String filePath ) {
        IdCard idCard = new IdCard();
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";
        try {

            // 本地文件路径
            //String filePath2 = "C:\\Users\\Administrator\\Desktop\\新建文件夹\\20230505094114.jpg";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            //byte[] imgData = filePath.getBytes();
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "id_card_side=" + "front" + "&image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = getToken().get("access_token");

            String result = HttpUtil.post(url, accessToken, param);
            //System.err.println(result);
            IdCardObj idCardObj = JSONObject.parseObject(result, IdCardObj.class);
            //System.err.println(idCardObj);
            String words_result = idCardObj.getWords_result();
            //System.out.println("words_result:"+words_result);
            Map<String,Object> map = JSONObject.parseObject(words_result, Map.class);
            //System.out.println("words_result:"+map);
            for (String s : map.keySet()) {
                //System.out.println("key:"+s);

                Map<String,String> mapName = JSONObject.parseObject(JSONObject.toJSONString(map.get(s)), Map.class);
                //System.out.println("mapName:"+mapName);
                if (s.equals("姓名")){
                    idCard.setName(mapName.get("words"));
                }
                if (s.equals("民族")){
                    idCard.setNationality(mapName.get("words"));
                }
                if (s.equals("住址")){
                    idCard.setFrom(mapName.get("words"));
                }
                if (s.equals("公民身份号码")){
                    idCard.setIdc(mapName.get("words"));
                    if (StringUtils.isNotEmpty(idCard.getIdc())){
                        Integer age = getAge(idCard.getIdc());
                        idCard.setAge(age);
                    }
                }
                if (s.equals("出生")){
                    idCard.setBirthday(mapName.get("words"));
                }
                if (s.equals("性别")){
                    idCard.setGender(mapName.get("words"));
                }


            }
            //String name = map.get("姓名");
            //Map<String,String> mapName = JSONObject.parseObject(JSONObject.toJSONString(name), Map.class);
            //System.out.println("mapName:"+mapName);
            //String words = mapName.get("words");
            //System.out.println("名称:"+words);
            System.out.println("身份证信息:"+idCard);
            //身份证信息:IdCard(name=廖春香, nationality=汉, from=湖南省宁乡县喻家坳乡南岭村银家组14号, idc=43012419900118564X, birthday=19900118, gender=女)
            return idCard;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //识别行驶证
    public static CarInfo vehicleLicense(String filePath) {

        CarInfo carInfo = new CarInfo();
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/vehicle_license";
        try {
            // 本地文件路径
            //filePath = "C:\\Users\\Administrator\\Desktop\\新建文件夹\\20230511154455.jpg";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = getToken().get("access_token");

            String result = HttpUtil.post(url, accessToken, param);
            log.error("返回的信息:",result);
            //{"log_id":1686291770894114063,"error_msg":"image size error","error_code":216202}
            if (result.contains("error_msg")){
                Map<String,String> map = JSONObject.parseObject(result, Map.class);
                String error_msg = map.get("error_msg");
                throw new CustomException(error_msg,400);
            }
            IdCardObj idCardObj = JSONObject.parseObject(result, IdCardObj.class);
            String words_result = idCardObj.getWords_result();
            Map<String,Object> map = JSONObject.parseObject(words_result, Map.class);
            if (!Objects.isNull(map.get("error_msg")) ){
                throw new CustomException((String) map.get("error_msg"),400);
            }
            for (String s : map.keySet()) {
                //System.out.println("key:"+s);

                Map<String,String> mapName = JSONObject.parseObject(JSONObject.toJSONString(map.get(s)), Map.class);
                //System.out.println("mapName:"+mapName);
                if (s.equals("车辆识别代号")){
                    carInfo.setVehicle_identification_code(mapName.get("words"));
                }
                if (s.equals("住址")){
                    carInfo.setAddress(mapName.get("words"));
                }
                if (s.equals("发证日期")){
                    carInfo.setDate_issue(mapName.get("words"));
                }

                if (s.equals("发证单位")){
                    carInfo.setIssuing_unit(mapName.get("words"));
                }
                if (s.equals("品牌型号")){
                    carInfo.setBrand_model(mapName.get("words"));
                }
                if (s.equals("车辆类型")){
                    carInfo.setVehicle_type(mapName.get("words"));
                }if (s.equals("所有人")){
                    carInfo.setAll(mapName.get("words"));
                }
                if (s.equals("使用性质")){
                    carInfo.setNature_use(mapName.get("words"));
                }
                if (s.equals("号牌号码")){
                    carInfo.setPlate_number(mapName.get("words"));
                }if (s.equals("注册日期")){
                    carInfo.setDate_registration(mapName.get("words"));
                }
            }
            System.out.println("行驶证信息:"+carInfo);
            //行驶证信息:CarInfo(vehicle_identification_code=LE40B8EB2ML623590, address=湖南省长沙市雨花区东山街道南雅社区香樟东路299号南雅社区万里时代4栋1908室, date_issue=20201123, Issuing_unit=湖南省长沙市公安局交通警察支队, brand_model=梅赛德斯-奔驰牌BJ6486L, vehicle_type=小型普通客车, all=卢利华, nature_use=非营运, plate_number=湘A59GC9, date_registration=20201123)
            //行驶证信息:CarInfo(vehicle_identification_code=LE40B8EB2ML623590, address=湖南省长沙市雨花区东山街道南雅社区香樟东路299号南雅社区万里时代4栋1908室, date_issue=20201123, Issuing_unit=湖南省长沙市公安局交通警察支队, brand_model=梅赛德斯-奔驰牌BJ6486L, vehicle_type=小型普通客车, all=卢利华, nature_use=非营运, plate_number=湘A59GC9, date_registration=20201123)
            return carInfo;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     * 根据身份证号获取年龄
     * @param IDCard
     * @return
     */
    public static Integer getAge(String IDCard){
        Integer age = 0;
        Date date = new Date();
        if (StringUtils.isNotBlank(IDCard)&& isValid(IDCard)){
            //15位身份证号
            if (IDCard.length() == FIFTEEN_ID_CARD){
                // 身份证上的年份(15位身份证为1980年前的)
                String uyear = "19" + IDCard.substring(6, 8);
                // 身份证上的月份
                String uyue = IDCard.substring(8, 10);
                // 当前年份
                String fyear = format.format(date).substring(0, 4);
                // 当前月份
                String fyue = format.format(date).substring(5, 7);
                if (Integer.parseInt(uyue) <= Integer.parseInt(fyue)) {
                    age = Integer.parseInt(fyear) - Integer.parseInt(uyear) + 1;
                    // 当前用户还没过生
                } else {
                    age = Integer.parseInt(fyear) - Integer.parseInt(uyear);
                }
                //18位身份证号
            }else if(IDCard.length() == EIGHTEEN_ID_CARD){
                // 身份证上的年份
                String year = IDCard.substring(6).substring(0, 4);
                // 身份证上的月份
                String yue = IDCard.substring(10).substring(0, 2);
                // 当前年份
                String fyear = format.format(date).substring(0, 4);
                // 当前月份
                String fyue = format.format(date).substring(5, 7);
                // 当前月份大于用户出身的月份表示已过生日
                if (Integer.parseInt(yue) <= Integer.parseInt(fyue)) {
                    age = Integer.parseInt(fyear) - Integer.parseInt(year) + 1;
                    // 当前用户还没过生日
                } else {
                    age = Integer.parseInt(fyear) - Integer.parseInt(year);
                }
            }
        }
        return age;
    }

    /**
     * 身份证验证
     * @param id 号码内容
     * @return 是否有效
     */
    public static boolean isValid(String id){
        Boolean validResult = true;
        //校验长度只能为15或18
        int len = id.length();
        if (len != FIFTEEN_ID_CARD && len != EIGHTEEN_ID_CARD){
            validResult = false;
        }
        //校验生日
        if (!validDate(id)){
            validResult = false;
        }
        return validResult;
    }

    /**
     * 校验生日
     * @param id
     * @return
     */
    private static boolean validDate(String id)
    {
        try
        {
            String birth = id.length() == 15 ? "19" + id.substring(6, 12) : id.substring(6, 14);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Date birthDate = null;
            birthDate = sdf.parse(birth);

            if (!birth.equals(sdf.format(birthDate))){
                return false;
            }
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

        return true;
    }
}
